#include"Queue.h"


void QueueInit(Queue* q) {
	assert(q);
	q->head = q->tail = NULL;
	q->size = 0;
}

void QueuePush(Queue* q, QDataType data) {
	assert(q);
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	newnode->data = data;
	newnode->next = NULL;
	assert(newnode);
	if (q->size == 0) {
		q->head =q->tail= newnode;
	}
	else
	{
		q->tail->next = newnode;
		q->tail = q->tail->next;
	}
	q->size++;
}

void QueuePop(Queue* q) {
	assert(q);
	QNode* first = q->head;
	q->head = first->next;
	free(first);
	first = NULL;
	q->size--;
}

QDataType QueueFront(Queue* q) {
	assert(q);
	return q->head->data;
}

QDataType QueueBack(Queue* q) {
	assert(q);
	return q->tail->data;
}
int QueueSize(Queue* q) {
	assert(q);
	return q->size;
}
int QueueEmpty(Queue* q) {
	assert(q);
	return !q->size;
}
void QueueDestroy(Queue* q) {
	assert(q);
	if (q == NULL)
		return;
	QNode* cur = q->head;
	while (cur) {
		q->head = q->head->next;
		free(cur);
		cur = q->head;
	}
}